import { BaseWindow } from "../../../../component/window/BaseWindow";
import { ILayer } from "../../../../mvc/interfaces/ILayer";
import { Language } from "../../../../../extend/language/Language";
import { ObjCreate } from "../../common/ObjCreate";
import { PetHireInfoPanel } from "../../petHire/PetHireInfoPanel";
import { PublicMessageConfig } from "../../../resource/PublicMessageConfig";
import { Cache } from "../../../cache/Cache";
import { EArenaChooseGroupState } from "../../../../../Message/Public/EArenaChooseGroupState";
import { MuiEvent } from "../../../../../com/mui/events/MuiEvent";
import { MsgManager } from "../../../manager/MsgManager";
import { ArenaCrossGroupSeaResultPanel } from "./ArenaCrossGroupSeaResultPanel";
import { ArenaCrossGroupMyServerPanel } from "./ArenaCrossGroupMyServerPanel";
import { ArenaCrossGroupSelectPanel } from "./ArenaCrossGroupSelectPanel";
import { ArenaCrossGroupResultPanel } from "./ArenaCrossGroupResultPanel";
import { SArenaCrossToplists } from "../../../../../Message/Public/SArenaCrossToplists";
import { SArenaCrossGroupMembers } from "../../../../../Message/Public/SArenaCrossGroupMembers";
import { GTabBar } from "../../../../../com/mui/controls/GTabBar";
import { GButton } from "../../../../../com/mui/controls/GButton";
type int = number;
//class ArenaCrossGroupMatchMainWindow
    
    export  class ArenaCrossGroupMatchMainWindow extends BaseWindow
    {
        constructor(arg1: ILayer=null)
        {
            super(arg1);
            this._tabBarData = new Array<any>();
            setSize(838, 555);
            titleHeight = 48;
            title = Language.getString(44280);
            return;
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            this._tabBar = ObjCreate.createGTabBar(23, 34, this._tabBarData, 75, 22, this, this.onTabChange);
            this.resetTabBar();
            this.initPanels();
            this._btnHelp = ObjCreate.createGButton(Language.getString(42235), 750, 33, 70, 22, this, "Button");
            this._infoPanel = new PetHireInfoPanel();
            this._infoPanel.visible = false;
            this._infoPanel.x = 835;
            this._infoPanel.y = 40;
            var loc1=PublicMessageConfig.instance.getArenaTextByName("arenaCrossGroupMatchHelpDesc");
            this._infoPanel.updateByContent(loc1);
            this.addChild(this._infoPanel);
            this._btnHelp.addEventListener(flash.events.MouseEvent.CLICK, this.onHelpBtn);
            if (Cache.instance.arenaCross.isSelfPromotion() && Cache.instance.arenaCross.arenaCrossInfo && Cache.instance.arenaCross.arenaCrossInfo.chooseGroupState == EArenaChooseGroupState._EArenaChooseGroupStart) 
            {
                this.changeTabIndex(2);
            }
            return;
        }

        /* internal  */onHelpBtn(arg1: Object /* flash.events.MouseEvent */): void
        {
            this._infoPanel.visible = !this._infoPanel.visible;
            return;
        }

        /* internal  */resetTabBar(): void
        {
            this._tabBarData = [];
            this._tabBarData.push({"label": Language.getString(44284), "name":"name1"});
            this._tabBarData.push({"label": Language.getString(44285), "name":"name2"});
            if (Cache.instance.arenaCross.isSelfPromotion()) 
            {
                this._tabBarData.push({"label": Language.getString(44286), "name":"name3"});
            }
            this._tabBarData.push({"label": Language.getString(44287), "name":"name4"});
            this._tabBar.dataProvider = this._tabBarData;
            return;
        }

        /* internal  */onTabChange(arg1: MuiEvent): void
        {
            var loc1=arg1.selectedIndex;
            this.changeTabIndex(loc1);
            return;
        }

        /* internal  */changeTabIndex(arg1: int): void
        {
            this._tabBar.selectedIndex = arg1;
            var loc1=this.getPanelByIndex(arg1);
            if (loc1 == this._groupResultPanel && Cache.instance.arenaCross.arenaCrossInfo && !(Cache.instance.arenaCross.arenaCrossInfo.chooseGroupState == EArenaChooseGroupState._EArenaChooseGroupSystemDeal)) 
            {
                this._tabBar.selectedIndex = this.lastIndex;
                MsgManager.showRollTipsMsg(Language.getString(44288));
                return;
            }
            this.lastIndex = arg1;
            if (this._selectPanel && this._selectPanel.parent) 
            {
                this._selectPanel.parent.removeChild(this._selectPanel);
            }
            this.addChild(loc1);
            this._selectPanel = loc1;
            return;
        }

        /* internal  */initPanels(): void
        {
            this._seaResultPanel = new ArenaCrossGroupSeaResultPanel();
            ObjCreate.setObjAttri(this._seaResultPanel, 18, 60, -1, -1, this);
            this._selectPanel = this._seaResultPanel;
            this._myServerPanel = new ArenaCrossGroupMyServerPanel();
            ObjCreate.setObjAttri(this._myServerPanel, 18, 60);
            this._groupSelectPanel = new ArenaCrossGroupSelectPanel();
            ObjCreate.setObjAttri(this._groupSelectPanel, 18, 60);
            this._groupResultPanel = new ArenaCrossGroupResultPanel();
            ObjCreate.setObjAttri(this._groupResultPanel, 18, 60);
            return;
        }

        /* internal  */getPanelByIndex(arg1: int): Object /* flash.display.DisplayObject */
        {
            var loc1=this._tabBarData[arg1];
            if (!loc1.hasOwnProperty("name")) 
            {
                return null;
            }
            var loc2=loc1["name"];
            switch (loc2) 
            {
                case "name1":
                {
                    return this._seaResultPanel;
                }
                case "name2":
                {
                    return this._myServerPanel;
                }
                case "name3":
                {
                    return this._groupSelectPanel;
                }
                case "name4":
                {
                    return this._groupResultPanel;
                }
                default:
                {
                    return null;
                }
            }
        }

        public updateTopList(arg1: SArenaCrossToplists): void
        {
            if (this._selectPanel == this._seaResultPanel) 
            {
                this._seaResultPanel.updateArenaCrossTopList(arg1);
            }
            if (this._selectPanel == this._myServerPanel) 
            {
                this._myServerPanel.updateArenaCrossTopList(arg1);
            }
            return;
        }

        public updateGroupNumData(arg1: Array<any>): void
        {
            if (this._groupSelectPanel) 
            {
                this._groupSelectPanel.updateGroupNumData(arg1);
            }
            return;
        }

        public updateGroupMembers(arg1: SArenaCrossGroupMembers): void
        {
            if (this._groupResultPanel) 
            {
                this._groupResultPanel.updateGroupMembers(arg1);
            }
            return;
        }

        public /* override */ show(arg1: int=0, arg2: int=0): void
        {
            var loc1=this._tabBarData.length;
            this.resetTabBar();
            var loc2=this._tabBarData.length;
            if (loc1 != loc2) 
            {
                if (loc2 != 4) 
                {
                    this.changeTabIndex(0);
                }
                else 
                {
                    this.changeTabIndex(2);
                }
            }
            super.show(arg1, arg2);
            return;
        }

        /* internal */ /* var */_tabBarData: Array<any>;

        /* internal */ /* var */_tabBar: GTabBar;

        /* internal */ /* var */_seaResultPanel: ArenaCrossGroupSeaResultPanel;

        /* internal */ /* var */_myServerPanel: ArenaCrossGroupMyServerPanel;

        /* internal */ /* var */_groupSelectPanel: ArenaCrossGroupSelectPanel;

        /* internal */ /* var */_groupResultPanel: ArenaCrossGroupResultPanel;

        /* internal */ /* var */_btnHelp: GButton;

        /* internal */ /* var */_infoPanel: PetHireInfoPanel;

        /* internal */ /* var */_selectPanel: Object /* flash.display.DisplayObject */;

        /* internal */ /* var */lastIndex: int=0;
    }
